using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BT_Q1000
{
    public partial class frmImportSettings : Form
    {
        public frmImportSettings()
        {
            InitializeComponent();
        }


        private void numericStartPOI_ValueChanged(object sender, EventArgs e)
        {
            if (numericStartPOI.Value >= numericEndPOI.Value)
            {
                MessageBox.Show("Start POI index must be smaller than end POI index!", "BT-Q1000 Settings");
                numericStartPOI.Value--;
            }
        }

        private void numericEndPOI_ValueChanged(object sender, EventArgs e)
        {
            if (numericEndPOI.Value <= numericStartPOI.Value)
            {
                MessageBox.Show("End POI index must be greater than start POI index!", "BT-Q1000 Settings");
                numericEndPOI.Value++;
            }
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            if (chkIgnoreFirstRecords.Checked)
                ReaderSettings.GetInstance().IgnoredFirstRecords = (int) numericIgnoreFirstPositions.Value;

            ReaderSettings.GetInstance().Convert1HzTo5Hz = chkContains1HzAnd5Hz.Checked && radioConvert1HzTo5Hz.Checked;
            ReaderSettings.GetInstance().IgnoreNon5HzPositions = chkContains1HzAnd5Hz.Checked && radioIgnoreNon5HzPositions.Checked;

            if (radioPOIFIlter.Checked)
            {
                ReaderSettings.GetInstance().UsePOI = true;
                ReaderSettings.GetInstance().UseDateTime = false;
                ReaderSettings.GetInstance().StartPoiIndex = (int) numericStartPOI.Value;
                ReaderSettings.GetInstance().EndPoiIndex = (int) numericEndPOI.Value;
            }
            else if (radioDateTimeFilter.Checked)
            {
                ReaderSettings.GetInstance().UsePOI = false;
                ReaderSettings.GetInstance().UseDateTime = true;
                ReaderSettings.GetInstance().StartDateTime = dateTimeStart.Value;
                ReaderSettings.GetInstance().EndDateTime = dateTimeEnd.Value;
            }
            else
            {
                ReaderSettings.GetInstance().UsePOI = false;
                ReaderSettings.GetInstance().UseDateTime = false;
            }

            this.Close();
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void radioFilterData_CheckedChanged(object sender, EventArgs e)
        {
            if (radioPOIFIlter.Checked)
            {
                numericStartPOI.Enabled = true;
                numericEndPOI.Enabled = true;
            }
            else
            {
                numericStartPOI.Enabled = false;
                numericEndPOI.Enabled = false;
            }
        }

        private void dateTimeStart_ValueChanged(object sender, EventArgs e)
        {
            if (DateTime.Compare(dateTimeStart.Value, dateTimeEnd.Value) > 0)
            {
                MessageBox.Show("Start date must be before end date!", "BT-Q1000 Settings");
                dateTimeStart.Value = dateTimeEnd.Value.Subtract(TimeSpan.FromSeconds(1));
            }

        }

        private void dateTimeEnd_ValueChanged(object sender, EventArgs e)
        {
            if (DateTime.Compare(dateTimeStart.Value, dateTimeEnd.Value) > 0)
            {
                MessageBox.Show("End date must be after start date!", "BT-Q1000 Settings");
                dateTimeEnd.Value = dateTimeStart.Value.Add(TimeSpan.FromSeconds(1));
            }
        }

        private void radioDateTimeFilter_CheckedChanged(object sender, EventArgs e)
        {
            if (radioDateTimeFilter.Checked)
            {
                dateTimeStart.Enabled = true;
                dateTimeEnd.Enabled = true;
            }
            else
            {
                dateTimeStart.Enabled = false;
                dateTimeEnd.Enabled = false;
            }
        }

        private void chkIgnoreFirstRecords_CheckedChanged(object sender, EventArgs e)
        {
            numericIgnoreFirstPositions.Enabled = chkIgnoreFirstRecords.Checked;
        }

        private void chkContains1HzAnd5Hz_CheckedChanged(object sender, EventArgs e)
        {
            if (chkContains1HzAnd5Hz.Checked)
            {
                radioConvert1HzTo5Hz.Enabled = true;
                radioIgnoreNon5HzPositions.Enabled = true;
            }
            else
            {
                radioConvert1HzTo5Hz.Enabled = true;
                radioIgnoreNon5HzPositions.Enabled = true;
            }

        }

        private void radioPOIFIlter_CheckedChanged(object sender, EventArgs e)
        {
            if (radioPOIFIlter.Checked)
            {
                numericStartPOI.Enabled = true;
                numericEndPOI.Enabled = true;
            }
            else
            {
                numericStartPOI.Enabled = false;
                numericEndPOI.Enabled = false;
            }
        }


     

      
    }
}